export function _debounce(fn, delay) {
  // let timer = null;
  let timer;
  return function () {
    let context = this;
    let args = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() => {
      timer = null;
      fn.apply(context, args);
    }, delay);
  }
}

export function _throttle(fn, delay) {
  var last;
  var timer;
  var delay = delay || 200;
  return function () {
      var th = this;
      var args = arguments;
      var now = +new Date();
      if (last && now - last < delay) {
          clearTimeout(timer);
          timer = setTimeout(function () {
              last = now;
              fn.apply(th, args);
          }, delay);
      } else {
          last = now;
          fn.apply(th, args);
      }
  }
}